<template>
	<view>
		<button v-if="is_style=='button'" class="flex j-c a-c b_y cff but_login f28" style="background-color: #2932E1;"
			open-type="getUserInfo" @getuserinfo="on_login">
			百度授权登录
		</button>

		<view v-if="is_style=='img'">
			<button open-type="getUserInfo" @getuserinfo="on_login">
				<image class="q_y login_icon" src="@/static/icon/baidu.png"></image>
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "login-mp-ali",
		props: {
			userName: {
				type: String,
				default: ''
			},
			avatarUrl: {
				type: String,
				default: ''
			},
			agr: {
				type: Boolean,
				default: false
			},
			agr: {
				type: Boolean,
				default: false
			},
			is_style: {
				type: String,
				default: 'button'
			},
		},
		data() {
			return {}
		},
		created() {
			this.face = this.avatarUrl;
			this.nickname = this.userName;
		},
		methods: {
			on_login(e) {
				let that = this;
				if (!this.agr) {
					uni.showToast({
						title: '请勾选同意协议',
						icon: "none"
					});
					return;
				}
				//百度小程序授权登录
				var userInfo = e.detail.userInfo;
				that.nickname = userInfo.nickName;
				that.face = userInfo.avatarUrl;
				that.sex = userInfo.gender
				uni.showLoading({
					title: '正在登录中...',
					mask: true
				})
				uni.getLoginCode({
					success(res) {
						var code = res.code;
						let requestParams = {
							baidu_code: code,
							face: that.face,
							nickname: that.nickname,
							sex: 0,
						};
						that.Banmikeji.mp_baidu_login(requestParams).then(ret => {
							uni.hideLoading()
							that.$emit('confirm', ret);
						})
					},
					fail(res2) {
						uni.showToast({
							title: '授权后即可登录',
							icon: 'error'
						})
					}
				});
		 
			},

		}
	}
</script>
<style lang="scss">
	.but_login {
		width: 600rpx;
		height: 80rpx;
		background-color: #1DC069;
	}

	button::after {
		border: none;
	}

	button {

		border: 0;
		padding: 0;
		background-color: transparent;

	}
</style>